package com.jnsjcc.freemarker.controller;

import java.util.Collection;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.ProviderManager;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.jnsjcc.freemarker.service.EntityService;

@Controller
public class IndexController {
    
    @Autowired
    private EntityService service; 
    
    

    @RequestMapping(value = "/index")
    public String index(Map<String, Object> retMap) {
        
        
        return "index/index";

    }
    
    @RequestMapping(value = "/secure")
    public String secure(Map<String, Object> retMap) {
        
        UserDetails loginUser = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        System.out.println(loginUser.getUsername());
        
        return "view/secure";
        
    }
    
    @RequestMapping(value = "/adminrole")
    public String adminrole(Map<String, Object> retMap) {
        
        UserDetails loginUser = (UserDetails) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        
        Collection<? extends GrantedAuthority> authorities = loginUser.getAuthorities();
        for (GrantedAuthority grantedAuthority : authorities) {
            System.out.println(grantedAuthority);
            
        }
        
        return "view/adminrole";
        
    }
    
    
    
    
    @RequestMapping(value = "/login")
    public String login(Map<String, Object> retMap) {
        
        return "login/login";
        
    }
    
    @RequestMapping(value = "/logintarget")
    public String logintarget(Map<String, Object> retMap) {
        
        return "view/login_target";
        
    }
    
    @RequestMapping(value="/err")
    public String err(){
        return "err/err";
    }

}
